/****************************************************************************
 *  QLyrics - A simple lyrics viewer.                                       *
 *  Copyright (C) 2008  hsys <hanshuiys@gmail.com>                          *
 *                                                                          *
 *  This program is free software; you can redistribute it and/or modify    *
 *  it under the terms of the GNU General Public License as published by    *
 *  the Free Software Foundation; either version 3 of the License, or       *
 *  (at your option) any later version.                                     *
 *                                                                          *
 *  This program is distributed in the hope that it will be useful,         *
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of          *
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           *
 *  GNU General Public License for more details.                            *
 *                                                                          *
 *  You should have received a copy of the GNU General Public License       *
 *  along with this program; if not, write to the Free Software Foundation, *
 *  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA       *
 ****************************************************************************/

#include "lyricsdownloadwindow.h"
#include <QStringList>
#include "lyricsprovider.h"

LyricsDownloadWindow::LyricsDownloadWindow(LyricsJob* job, QWidget* parent) : QDialog(parent) {
    ui.setupUi(this);

    m_provider = job->getCurrentProvider();

    // set track information
    m_track = m_provider->getTrack();
    ui.txtTitle->setText(m_track.title);
    ui.txtAlbum->setText(m_track.album);
    ui.txtArtist->setText(m_track.artist);

    // add results
    int i;
    LyricsProvider::const_iterator px;
    ui.lstResult->clear();
    for (i = 1, px = m_provider->resultBegin(); px != m_provider->resultEnd(); ++px, ++i) {
        new QTreeWidgetItem(ui.lstResult, QStringList() << QString::number(i)
                << px->title << px->artist << px->album << px->preview);
    };
};

void LyricsDownloadWindow::accept() {
    m_provider->acceptResult(ui.lstResult->currentItem()->text(0).toInt() - 1);
    QDialog::accept();
};

void LyricsDownloadWindow::reject() {
    m_provider->cancelResult();
    QDialog::reject();
};
